<template>
	<view class="container"
	 :style="{minHeight: systemInfo.windowHeight+'px'}">
	 <!-- 登录提示 -->
	 <zr-show-model />
		<view class="box-2">
			<view class="but" @click="getUserProfile">授权登录</view>
		</view>
	</view>
</template>
<script>
	import { sociallogin, getUserInfo } from "@/api/login.js"
	import { setToken } from '@/utils/auth'
	import encryption from '@/common/encryption.js'
	export default {
		data() {
			return {
				systemInfo: uni.getSystemInfoSync(),
				userInfo: {}
			}
		},
		computed: {
			currentDate() {
				// let date = new Date()
				// let hours = date.getHours()
				// if (hours >= 0 && hours < 11) return '凌晨好'
				// if (hours >= 11 && hours < 14) return '中午好'
				// if (hours >= 14 && hours < 18) return '下午好'
				// if (hours >= 18 && hours < 24) return '晚上好'
				// return '您好'
			}
		},
		onLoad() {

		},
		methods: {
			selectCk:function(e){
				this.namesel=e.detail.value
			},
			
			getUserProfile () {
				uni.showLoading({mask: true,title: '请稍后...'})
				uni.getUserProfile({
					desc: '用于完善会员资料',
					lang: 'zh_CN',
					success: (userRes) => {
						console.log(userRes.userInfo)
						this.userInfo = Object.assign(this.userInfo,userRes.userInfo)
						uni.login({
							provider: 'weixin',
							success: async (loginRes) => {
								console.log(loginRes.code)
								this.get_openID(loginRes.code)
							}
						})
					},
					fail: (err) => {
						uni.hideLoading();
						uni.showToast({
							icon: "none",
							title: '授权失败'
						})
					}
				})
			},
			// 获取openid
			async get_openID(code) {
				sociallogin(code).then(response => {
					// 记录用户信息
					console.log('response.accessToken', response);
					console.log("9090",response.data.accessToken);
					setToken(response.data.accessToken)
					commit('SET_TOKEN', response.data.accessToken)
					console.log(2); 
					resolve()  
					this.quickLogin()
					
				})
			},
			async quickLogin() {
				// const data = uni.getStorageSync('socialLogin')
				getUserInfo().then(response => {
					// 记录用户信息
					console.log('用户信息', response)
				})
					// let res = await this.$request({
					// 	url: 'Login/quick_login',
					// 	method: 'POST',
					// 	data: {
					// 		openid: this.userInfo.openId,
					// 		heardimg: this.userInfo.avatarUrl,
					// 		nickname: this.userInfo.nickName,
					// 		source: this.source,
					// 	}
					// })
					
					// uni.hideLoading();
					// // 记录用户信息
					// uni.setStorage({
					// 	key: 'loginInfo',
					// 	data: {
					// 		token: res.token,
					// 		usersig: res.usersig,
					// 		user_id: res.user_id,
					// 		userInfo: res.userInfo,
					// 		timId: res.timId,
					// 	},
					// 	success: (e)=>{
					// 		this.$common.getLoginInfo()
					// 		uni.navigateBack()
					// 	}
					// })
			}
		}
	}
</script>

<style lang="scss">
	.container {
		display: flex;
		flex-direction: column;
		width: 750rpx;
		padding-top: var(--status-bar-height);
		justify-content: space-between;
		box-sizing: border-box;
		.box-1 {
			margin-top: 70rpx;
			width: 420rpx;
			height: 440rpx;
			background-size: 100%;
			background-repeat: no-repeat;
			margin-left: 20rpx;
			display: flex;
			flex-direction: column;
			box-sizing: border-box;
			padding: 180rpx 0 0 20rpx;
			.h1 {
				font-size: 80rpx;
				color: #333333;
			}
			.h2 {
				font-size: 48rpx;
				color: #333333;
			}
		}
		.box-2 {
			width: 750rpx;
			height: 690rpx;
			background-size: 100%;
			background-repeat: no-repeat;
			display: flex;
			flex-direction: column;
			align-items: center;
			box-sizing: border-box;
			padding: 310rpx 0 35rpx 0;
			justify-content: space-between;
			.but {
				width: 552rpx;
				height: 100rpx;
				background: #3F74FC;
				opacity: 1;
				border-radius: 45rpx;
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			.password {
				font-size: 28rpx;
				font-weight: 400;
				color: #3F74FC;
				margin-bottom: 120rpx;
			}
			.appleSign {
				width: 550rpx;
				height: 90rpx;
				background-color: #FFFFFF;
				border: 1px solid #0C0C0C;
				margin: 20rpx;
				border-radius: 50rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #404657;
				font-size: 32rpx;
				color: #404657;
				.iconfont {
					font-size: 34rpx;
					margin-right: 8rpx;
				}
			}
			.quick {
				display: flex;
				align-items: center;
				width: 	670rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-bottom: 60rpx;
				margin-top: 20rpx;
				.icon-weixin1 {
					height: 80rpx;
					width: 80rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 50rpx;
					color: #09BA06;
					border: 1px solid #CCCCCC;
					background-color: #FFFFFF;
					border-radius: 50%;
				}
				// .text {
				// 	font-size: 24rpx;
				// 	font-weight: 400;
				// 	color: #999999;
				// 	margin-top: 20rpx ;
				// }
			}
			.protocol {
				font-size: 24rpx;
				font-weight: 400;
				color: #999999;
				.text {
					color: #3F74FC;
				}
			}
		}
	}
</style>
